//
//  DynamicMainViewController.m
//  OAProject
//
//  Created by yhj on 2017/2/20.
//  Copyright © 2017年 cdnunion. All rights reserved.
//  动态主界面

#import "DynamicMainViewController.h"
#import "WorkTableViewCell.h"

static NSString *tableViewCellIdentifier=@"UITableViewCellIdentifier";
@interface DynamicMainViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *goalMainTableView;

@end

@implementation DynamicMainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

     self.title=@"消息";

    [self initTableView];

}

-(void)initTableView
{
    // goalMainTableView
    _goalMainTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,0,APPW,APPH-49) style:UITableViewStylePlain];
    _goalMainTableView.delegate=self;
    _goalMainTableView.dataSource=self;
    _goalMainTableView.backgroundColor=MAIN_BACK_COLOR;
    _goalMainTableView.tableFooterView=[UIView new];
    [self.view addSubview:_goalMainTableView];
    [_goalMainTableView registerClass:[WorkTableViewCell class] forCellReuseIdentifier:tableViewCellIdentifier];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *arrImage=@[@"examine",@"task"];
    NSArray *arrTitle=@[@"放假通知",@"报销"];
    NSArray *arrDeTitle=@[@"放7天",@"通过"];

    WorkTableViewCell *cell=[[WorkTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableViewCellIdentifier];

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    cell.imageUrl.image=[UIImage imageNamed:arrImage[indexPath.section]];

    cell.nameLabel.text=arrTitle[indexPath.section];
    cell.nameLabel.textColor=DarkGreyColor;
    cell.nameLabel.font=Font_Number(18);

    cell.detailLabel.text=arrDeTitle[indexPath.section];
    cell.detailLabel.textColor=LightGreyColor;
    cell.detailLabel.font=Font_Number(13);

    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kmargin*6;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    [self.view makeToast:@"暂无" duration:.5 position:CSToastPositionCenter];

//    if (indexPath.row==0)
//    {
//        // 审批
//        ExamineViewController *examineViewController=[ExamineViewController new];
//        examineViewController.hidesBottomBarWhenPushed=YES;
//        [self.navigationController pushViewController:examineViewController animated:NO];
//    }

}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headView=[UIView new];
    headView.backgroundColor=BGColor;
    NSString *sectionStr;
    if (section==0)
    {
        sectionStr=@"公司消息";
    }
    else
    {
         sectionStr=@"个人消息";
    }
    UILabel *userLabel=[headView getLabelWithText:sectionStr font:Font_Number(13) textColor:Color333333 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
    [headView addSubview:userLabel];
    [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kmargin);
        make.top.mas_equalTo(kmargin/2);
    }];

    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kmargin*3;
}

// 间隙置边
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

@end
